package com.cjm.one.common.config.feign;


import com.cjm.one.common.interceptor.OneRequestInterceptor;
import feign.RequestInterceptor;
import feign.codec.Encoder;
import feign.form.spring.SpringFormEncoder;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.cloud.openfeign.support.SpringEncoder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.support.StandardServletMultipartResolver;

@Configuration
public class OneFeignClientConfiguration {
    @Bean
    public RequestInterceptor feignHeaderInterceptor () {
        return new OneRequestInterceptor();
    }

    @Bean
    public Encoder feignFormEncoder(ObjectFactory<HttpMessageConverters> converters) {
        // 使用 SpringFormEncoder 支持多部分文件上传
        return new SpringFormEncoder(new SpringEncoder(converters));
    }

    @Bean
    public MultipartResolver multipartResolver() {
        return new StandardServletMultipartResolver();
    }
}
